<?php
// get_plant.php/set?set=1&&srvip=192.168.2.126&&ip=192.168.2.114
// get_plant.php/set?set=1&&period=60&&ip=192.168.2.114
// get_plant.php/set?set=1&&val=400&&ip=192.168.2.114
if (isset($_REQUEST['ip'])) {
    $ip= $_REQUEST['ip'];

    if (isset($_REQUEST['get'])) {
        // 参数存在时的逻辑
        // echo "参数存在";
        $url = "http://". $ip ."/get?humidity=1";
        $ctx  = plant_get_status($url);
        echo $ctx;
    } else if (isset($_REQUEST['settings'])) {
        $url = "http://". $ip ."/get?settings=1";
        // echo $url;
        $ctx  = plant_get_status($url);
        echo $ctx;
    } else if (isset($_REQUEST['set']) && isset($_REQUEST['srvip'])) {
        // http://192.168.2.114/set?srvip=192.168.2.126
        $url = "http://". $ip ."/set?srvip=".$_REQUEST['srvip'];
        // echo $url;
        $ctx  = plant_get_status($url);
        echo $ctx;
    } else if (isset($_REQUEST['set']) && isset($_REQUEST['period'])) {
        // http://192.168.2.114/set?period=60
        $url = "http://". $ip ."/set?period=".$_REQUEST['period'];
        // echo $url;
        $ctx  = plant_get_status($url);
        echo $ctx;
    } else if (isset($_REQUEST['set']) && isset($_REQUEST['val'])) {
        // http://192.168.2.114/set?humidity=450
        $url = "http://". $ip ."/set?humidity=".$_REQUEST['val'];
        // echo $url;
        $ctx  = plant_get_status($url);
        echo $ctx;
    }
    else
    {
        echo "参数不存在";
    }
    

}

function plant_get_status($url){
    // $url = 'http://192.168.2.185'; // 网址
    $content = file_get_contents($url); // 获取网页内容
    // echo $content; // 输出网页内容
    return  $content;
}
?>